from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token

from apps.meiduo_admin.views import admin
from apps.meiduo_admin.views import group
from apps.meiduo_admin.views import home, user
from apps.meiduo_admin.views import image
from apps.meiduo_admin.views import order
from apps.meiduo_admin.views import permission
from apps.meiduo_admin.views import sku
from .views import *

# authorizations/
# router = DefaultRouter()
# router.register(r'skus', sku.SKUModelViewSet, basename='sku')

urlpatterns = [
    # url(r'authorizations/$', AdminLoginView.as_view()),
    # 　按照文档修改的 登陆
    # obtain_jwt_token 会进行用户名和密码的验证
    # 用户名和密码没有问题的话 会自动生成token
    url(r'^authorizations/$', obtain_jwt_token),
    # 查询所有用户
    url(r'^statistical/total_count/$', home.TotalUserCountAPIView.as_view()),
    # 日增用户
    url(r'^statistical/day_increment/$', home.DailyUserAddCountAPIView.as_view()),
    # 日活用户量
    url(r'^statistical/day_active/$', home.DailyUserActiveCountAPIView.as_view()),
    # 日增订单量
    url(r'^statistical/day_orders/$', home.UserDailyOrderCountAPIView.as_view()),
    # 月增用户折线图
    url(r'^statistical/month_increment/$', home.MonthUserCountAPIView.as_view()),
    # 日分类数据
    url(r'^statistical/goods_day_views/$', home.CategoryAPIView.as_view()),
    ##############################
    # 用户管理
    url(r'^users/$', user.UserListAPIView.as_view()),

    # # ------------图片管理------------
    # 　url(r'^skus/images/$',image.ImageModelViewSet.as_view()),
    # 图片sku_id 的简单获取
    url(r'^skus/simple/$', image.SimpleSKUAPIVIew.as_view()),

    #  －－－－－－－－－sku管理－－－－－－－－－
    # url(r'^', include(router.urls))
    # 获取三级分类
    url(r'^skus/categories/$', sku.ThreeCategoryListAPIView.as_view()),
    # 获取spu名称
    url(r'^goods/simple/$', sku.SimpleSPUListAPIView.as_view()),
    # 获取spu的规格选项
    url(r'^goods/(?P<pk>\d+)/specs/$', sku.SPUSpecsAPIView.as_view()),

    # ------ 权限管理 --------
    url(r'^permission/content_types/$', permission.ContentTypeAPIView.as_view()),
    # 组的权限修改
    url(r'^permission/simple/$', group.SimplePermissionAPIView.as_view()),
    # 管理员获取所有组
    url(r'^permission/groups/simple/$', admin.SimpleGroupListAPIView.as_view()),

]

# --------图片管理--------
# 1.创建router实例
router = DefaultRouter()
# 2.设置路由规则，注册视图集, images后面不需要加斜杠（/）
router.register(r'skus/images', image.ImageModelViewSet, basename='image')
# 3.将router中的路由追加到 urlpatterns
urlpatterns += router.urls

# ---------ｓｋｕ管理---------
router.register(r'skus', sku.SKUModelViewSet, basename='sku')
urlpatterns += router.urls

# -------订单管理路由--------
router.register(r'orders', order.OrderModelViewSet, basename='orders')
urlpatterns += router.urls

# ------权限路由--------
router.register(r'permission/perms', permission.PermissionModelViewSet, basename='perms')
urlpatterns += router.urls

# ------组路由-------
router.register(r'permission/groups', group.GroupModelViewSet, basename='groups')
urlpatterns += router.urls

# ------admin 路由------
router.register(r'permission/admins', admin.AdminModelViewSet, basename='admins')
urlpatterns += router.urls
